package product;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


public class CountYingtao {

	/**统计哪些农产品市场在售卖樱桃， 要标明农产品市场所在省份与城市
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		if (args.length!=2) {
			System.err.println("path err!");
			System.exit(-1);
		}
		Job job=new Job(new Configuration(), "Yingtao");
		job.setJarByClass(CountYingtao.class);
		FileInputFormat.addInputPath(job, new Path(args[0]));
		FileOutputFormat.setOutputPath(job, new Path(args[1]));
		job.setMapperClass(ymaps.class);
	
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(Text.class);

		job.waitForCompletion(true);

	}
	public static class ymaps extends Mapper<LongWritable,Text, Text, Text>{
		protected void map(LongWritable key, Text value, org.apache.hadoop.mapreduce.Mapper<LongWritable,Text,Text,Text>.Context context) throws java.io.IOException ,InterruptedException {
			String[] lines = value.toString().split("\t");
			if (lines.length==6 && lines[0].trim().contains("樱桃") && lines[0].length()==2) {
				String market = lines[3].trim();
				String provice = lines[4].trim();
				String city = lines[5].trim();
				context.write(new Text(market),new Text(provice+":"+city));
			}
		};
		
	}
	
}
